<?php
include_once('themes/head.php');	
include_once('controller/beritaController.php');
?>
	<?php
	
	if(isset($error_upload_berita))
	{
		echo '<div class="alert alert-error" id="alert">Salah ! '.$error_upload_berita.' 
			<button type="button" class="close" data-dismiss="alert" id="close">×</button></div>';
	}
	if(isset($success_upload_berita))
	{
		echo '<div class="alert alert-success">'.$success_upload_berita.'<button type="button" class="close" data-dismiss="alert" id="close">×</button></div>';
	}
	?>

<pre><h2>INFORMASI dan BERITA PERTANIAN </h2></pre>
	<div id="tombol_berita" class="controls">
		<?php
		if(isset($_SESSION['login']))
		{
		?>
		<button type="submit" name="tambah_berita" class="btn" id="tambah_btn" onclick="tambah_berita()">Tambah Berita</button>
		<button type="submit" name="edit_berita" class="btn" id="edit_btn" onclick="edit_berita()">Edit Berita</button>
		<?php
		}
		else
		{
		?>
		Login dahulu untuk Upload Berita dan Informasi
		<?php
		}
		?>
	</div>
	
	
<div id="beritaList">
	<table width="100" cellpadding="0" cellspacing="0" class="grid" style="width: 800px; margin: 0 auto 20px;">
	
	
	<?php
	if(isset($data))
	{
	foreach($data as $rows)
	{
	
	?>
		<tr>
		  <td width="870" colspan="4"><hr /></td>
		</tr>
		<tr>
			 <!--<td style="width: 30px;"><span class="checkbox" style="border: 0px;"><input no_berita="ctl00_content_rptProducts_ctl00_chkComparer" type="checkbox" name="ctl00$content$rptProducts$ctl00$chkComparer" onclick="javascript:addToCompareCart(this,&#39;SKU00209352&#39;);" /></span></td> -->
		 			 		 
			 
			<td style="width: 1000px; vertical-align: center; font-size: 1em; text-align: justify;">
			
				<a href="#"><?php echo '<img src="data:image/jpeg;base64,' . base64_encode(stripslashes($rows['gambar'] )) . '" />'; ?></a>
				<div class="orange" style="font-weight: bold;">
				<a style="font-weight: bold;" class="" href="#"><?php echo $rows['judul_berita']; ?></a>
				<div class="orange" style="font-weight: bold;" style=”text-align: justify;"> <?php echo $rows['isi_berita']; ?></a>
				<div class="blue" color="blue;" style="font-weight: bold;"> <br> <strong>Tanggal Posting: <?php echo $rows['tgl_berita']; ?></strong> </div>
				<a href="berita.php?edit&id=<?php echo $rows['no_berita'];?>">Edit</a>
		  </td>
			 
        </tr>
	<?php
		}
	}
	else
	{
	?>
		<tr>
			<td colspan="2">Berita Tidak Ada</td>
		</tr>
	<?php
	}
	?>
  </table>
  <div class="pagination pagination-mini">
		<ul>
		<?php
			$index=1;
			if(isset($_GET['page']))
			{
				$selected=$_GET['page'];
			}else
			{
				$selected=0;
			}
			
			if(isset($_GET['page']) && $_GET['page']!=0)
			{
				$prev=$_GET['page']-1;
				echo '<li class=""><a href="berita.php?page='.$prev.'">Prev</a></a></li>';				
			}
			elseif(isset($_GET['page']) && ($_GET['page'])==0)
			{
				echo '<li class="disabled"><a href="berita.php">Prev</a></a></li>';
			}			
			else
			{
				echo '<li class="disabled"><a href="berita.php">Prev</a></a></li>';
			}
			
			for($i=0;$i<$jml_hal;$i++)
			{	
				if($selected==$i)
				{
					echo '<li class="active"><a href="berita.php?page='.$i.'">'.$index.'</a></li>';
				}
				else
				{
					echo '<li class=""><a href="berita.php?page='.$i.'">'.$index.'</a></li>';
				}
				$index++;
			}	

			if(isset($_GET['page']) && ($jml_hal-1)!=$_GET['page'])
			{
				$next=$_GET['page']+1;
				echo '<li class=""><a href="berita.php?page='.$next.'">Next</a></a></li>';				
			}
			elseif(isset($_GET['page']) && ($jml_hal-1)==$_GET['page'])
			{
				echo '<li class="disabled"><a href="berita.php">Next</a></a></li>';
			}
			elseif($jml_hal==1)
			{
				echo '<li class="disabled"><a href="berita.php">Next</a></a></li>';
			}
			elseif(!isset($_GET['page']))	
			{
				$next=1;
				echo '<li class=""><a href="berita.php?page='.$next.'">Next</a></a></li>';
			}			
			else
			{
				$next=$_GET['page']+1;
				echo '<li class=""><a href="berita.php?page='.$next.'">Next</a></a></li>';
			}
		?>
		</ul>
	</div>
</div>

<div id="insertBerita" class="insertBerita">


	<form class="form-horizontal" method="post" action="#" enctype="multipart/form-data"  >
		<div class="control-group">
			<label class="control-label" for="inputBerita">Judul Berita</label>
				<div class="controls">
					<input type="text" cols="80" name="judul_berita" id="inputBerita" placeholder="Judul Berita">
				</div>
		</div>
		<div class="control-group">
			<label class="control-label" for="inputBerita">Isi Berita</label>
				<div class="controls">
				<textarea name="isi_berita" cols="100"  rows="20" id="inputBerita" placeholder="Isi Berita"> </textarea>
					
				</div>
		</div>
		
		<div class="control-group">
			<label class="control-label" for="inputBerita">Gambar Berita</label>
				<div class="controls">
					<input type="hidden" name="MAX_FILE_SIZE" value="60000">
					<input type="file" name="gambar_berita" id="inputBerita" placeholder="Gambar Berita">
				</div>
		</div>
		<div class="control-group">
			<div class="controls">
				<button type="submit" name="simpan_berita" class="btn" id="simpan_berita">Rekam Berita</button>
				<button type="submit" name="batal" class="btn" id="batal" onclick="batal()">Batal</button>
			</div>
		</div>
	</form>

</div>


<?php
	include_once('themes/footer.php');
?>



<script type="text/javascript">
	var url;
	function tambah_berita(){
		$('#beritaList').hide();	
		$('#tombol_berita').hide();		
		$('#insertBerita').show();
		return false;
	}
	function batal(){
		$('#beritaList').show();
		$('#tombol_berita').show();
		$('#insertBerita').hide();
		return false;
	}
	function edit_berita(){
		var id=document.getElementById('no_berita').value;
		}
</script>